import { param2Obj } from '@/utils'

const userMap = {
  admin: {
    data: {
      roles: ['admin'],
      token: 'admin',
      introduction: '我是超级管理员',
      avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      name: 'Super Admin'
    },
    code: '0000',
    msg: ''
  },
  editor: {
    data: {
      roles: ['editor'],
      token: 'editor',
      introduction: '我是编辑',
      avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      name: 'Normal Editor'
    },
    code: '0000',
    msg: ''
  }
}

export default {
  loginByUsername: config => {
    const { userName } = JSON.parse(config.body)
    return userMap[userName]
  },
  getUserInfo: () => {
    // const { token } = param2Obj(config.url)
    // if (userMap[token]) {
    //   return userMap[token]
    // } else {
    //   return false
    // }

    const userMapElement = userMap['admin']
    return userMapElement
  },
  logout: () => {
    return { code: '0000', msg: 'success' }
  }
}
